/**************************************************
 * 上海美峰数码科技有限公司(http://www.morefuntek.com)
 * 模块名称: GamePost
 * 功能描述：
 * 文件名：GamePost.java
 **************************************************
 */
package com.http.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

/**
 * 功能描述
 * 
 * @author YAOWENHAO
 * @since 2012-1-16
 * @version 1.0
 */
public class GamePost {
	HttpClient client = new DefaultHttpClient();

	public void post() {
		HttpPost post = new HttpPost("http://bbs.9game.cn/vote/vote.htm?id=6&P=OTHER_2011NDPX_TOPIC_WYPX&SessionId=501d6c78dda5a84c12f285bdab67a959");
		List<NameValuePair> formparams = new ArrayList<NameValuePair>();
		formparams.add(new BasicNameValuePair("Id", "6"));
		formparams.add(new BasicNameValuePair("VoteId", "11"));
		formparams.add(new BasicNameValuePair("Order", "1"));
		formparams.add(new BasicNameValuePair("ItemIds", "295")); //sg
		formparams.add(new BasicNameValuePair("ItemIds", "303")); //jw
		formparams.add(new BasicNameValuePair("sub", "	提交结果"));
		BufferedReader br = null;
		try {
			UrlEncodedFormEntity uef = new UrlEncodedFormEntity(formparams,
					HTTP.UTF_8);
			post.setEntity(uef);
			HttpResponse response = client.execute(post);
			HttpEntity entity = response.getEntity();
			System.out.println(response.getStatusLine());
			br = new BufferedReader(new InputStreamReader(entity.getContent(),
					"UTF-8"));
			String line = null;
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
	
	public static void main(String[] args) {
		GamePost game  = new GamePost();
		game.post();		
	}
}
